﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Interpreter.BuiltIns
{
	internal class SystemConsole : Module
	{
		public override void Register(FunctionRegistry functionRegistry)
		{
			functionRegistry.Register(1, new SystemConsolePrint());
			functionRegistry.Register(2, new SystemConsoleRead());
		}

		private class SystemConsolePrint : NativeFunction
		{
			public override Value Do(StackContext stackContext, Value[] args)
			{
				string value = stackContext.Args[0].ForceString(stackContext.Metadata);
				if (value == ":)")
				{

				}
				System.Console.WriteLine(value);
				return Value.Null;
			}
		}

		private class SystemConsoleRead : NativeFunction
		{
			public override Value Do(StackContext stackContext, Value[] args)
			{
				Value prompt = args[0];
				string promptString = "";
				if (prompt.Type != Value.TYPE_NULL)
				{
					promptString = prompt.ForceString(stackContext.Metadata);
				}

				System.Console.Write(promptString);
				string value = System.Console.ReadLine();

				return new Value(Value.TYPE_STRING, value);
			}
		}
	}
}
